package com.example.testactivity0323;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import org.w3c.dom.Text;

import java.util.EventListener;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    TextView tv1,tv2;
    public Button button1,button2,button3,button4,button5,button6,button7,button8;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

        public void init()
        {
            tv1 = (TextView)findViewById(R.id.stv1);
            tv2 = (TextView)findViewById(R.id.stv2);
            tv1.setText("当前动作");
        button1 = findViewById(R.id.button1);
        button2 = findViewById(R.id.button2);
        button3 = findViewById(R.id.button3);
        button4 = findViewById(R.id.button4);
        button5 = findViewById(R.id.button5);
        button6 = findViewById(R.id.button6);
        button7 = findViewById(R.id.button7);
        button8 = findViewById(R.id.button8);


        //1.ACTIVITY作为监听器
        button1.setOnClickListener(this);

        //2.定义一个内部类,实现View.OnClickListener接口,并重写onClick()方法
        button2.setOnClickListener(new BtnClickListener() );

        //3.匿名内部类作为监听器（就是new了一个view.onclicklistener）
        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "匿名内部类作为监听器，你点击了按钮", Toast.LENGTH_SHORT).show();
                tv2.setText("匿名内部类作为监听器");
            }
        });

        //4.lambda表达式作为事件监听类
            button4.setOnClickListener( (View view)->{

                     tv2.setText("lambda类作为监听器");
                    Toast.makeText(getApplicationContext(), "lambda类作为监听器，你点击了按钮", Toast.LENGTH_SHORT).show();
            });


        //5.外部类作为监听器
      //  button5.setOnClickListener(new Mybutton5click(this) );
            button5.setOnClickListener(new MyOnClickListener() {
                public void onClick(View view){
                    super.onClick(view);
                    tv2.setText("外部类作为监听器");
                    Toast.makeText(getApplicationContext(), "外部类作为监听器，你点击了按钮", Toast.LENGTH_SHORT).show();
                }
            });
         //7.获取系统配置
            button7.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.setClass(MainActivity.this,ConfigActivity.class);
                    startActivity(intent);
                }
            });
            //8.进度条

            button8.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.setClass(MainActivity.this,ProgressDialogTest.class);
                    startActivity(intent);
                }
            });



    }



    //6.绑定到标签
    public void getResult(View view){
        Toast.makeText(getApplicationContext(), "监听器绑定到标签，你点击了按钮", Toast.LENGTH_SHORT).show();
        tv2.setText("监听器绑定到按钮");
    }

    //7.系统信息





    //1.ACTIVITY作为监听器
    @Override
    public void onClick(View v) {
        Toast.makeText(getApplicationContext(), "activity作为监听器，你点击了按钮", Toast.LENGTH_SHORT).show();
        tv2.setText("activity作为监听器");
    }


    //2.定义一个内部类,实现View.OnClickListener接口,并重写onClick()方法
    class BtnClickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "内部类作为监听器，你点击了按钮", Toast.LENGTH_SHORT).show();
            tv2.setText("内部类作为监听器");
            //   TextView text1= findViewById(R.id.text1);
            //   text1.setText("匿名内部类作为监听使用了");
        }
    }




}

//5.外部类作为监听器
class MyOnClickListener implements View.OnClickListener{

    @Override
    public void onClick(View view) {

    }
}
